package com.jlu.yygh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jlu.yygh.common.exception.CustomException;
import com.jlu.yygh.common.result.ResultCodeEnum;
import com.jlu.yygh.mapper.HospitalSetMapper;
import com.jlu.yygh.model.hosp.HospitalSet;
import com.jlu.yygh.service.HospitalSetService;
import com.jlu.yygh.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper,HospitalSet> implements HospitalSetService {

  @Override
  public String getSignKey(String hoscode) {
    QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
    wrapper.eq("hoscode",hoscode);
    HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
    return hospitalSet.getSignKey();
  }

  //获取医院签名信息
  @Override
  public SignInfoVo getSignInfoVo(String hoscode) {
    QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
    wrapper.eq("hoscode",hoscode);
    HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
    if(null == hospitalSet) {
      throw new CustomException(ResultCodeEnum.HOSPITAL_OPEN);
    }
    SignInfoVo signInfoVo = new SignInfoVo();
    signInfoVo.setApiUrl(hospitalSet.getApiUrl());
    signInfoVo.setSignKey(hospitalSet.getSignKey());
    return signInfoVo;
  }
}
